﻿using System;

namespace Sidvall.SystemEnvironment.Windows
{
    public class Process : IProcess
    {
        #region Public Members

        public string ExitCode { get; private set; }
        public DateTime ExitTime { get; private set; }

        public void Close()
        {
            if (this.InternalProcess == null)
                return;
            this.InternalProcess.Close();
        }
        public void WaitForExit()
        {
            if (this.InternalProcess == null)
                return;
            this.InternalProcess.WaitForExit();
            InitializeExit();
        }
        public bool WaitForExit(int milliseconds)
        {
            if (this.InternalProcess == null)
                return true;
            var result = this.InternalProcess.WaitForExit(milliseconds);
            InitializeExit();
            return result;
        }

        #endregion
        #region Private Members

        private System.Diagnostics.Process InternalProcess { get; set; }

        #region InitializeExit

        private void InitializeExit()
        {
            this.ExitCode = this.InternalProcess.ExitCode.ToString(System.Globalization.CultureInfo.InvariantCulture);
            this.ExitTime = this.InternalProcess.ExitTime;
        }

        #endregion

        #endregion
        #region Constructors

        public Process(System.Diagnostics.Process process)
        {
            this.InternalProcess = process;
        }

        #endregion
    }
}
